<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>科目设置</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/left.css">
    <link rel="stylesheet" href="css/jquery.dialogbox.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/vue.js"></script>
    <script src="js/xcConfirm.js"></script>
    <script src="js/jquery.dialogBox.js"></script>
    <style type="text/css">
        .sgBtn{width: 135px; height: 35px; line-height: 35px; margin-left: 10px; margin-top: 10px; text-align: center; background-color: #0095D9; color: #FFFFFF; float: left; border-radius: 5px;}
        .bg {
            background:url(images/subject/bg1.jpg) no-repeat center fixed;
            background-size:100%;
        }
        .bgcon{
           background: white;
            opacity:0.9;
        }
        .bghead{

            padding-top: 10px;

        }
        .tithead{
            margin-left:10px;
            margin-bottom: 10px;
        }


    </style>
    <script>
        $(function(){
            var vue = new Vue({
                el:'#app',
                data:{
                    url:'http://localhost:8889/Subject',
                    subject:{},
                    subjects:[]
                },
                methods:{
                    query:function () {
                        var that = this;
                        $.getJSON(that.url+'/query',function(data){
                            that.subjects = data;
                        })
                    },
                    find:function(subject){
                        this.subject = subject;
                        $('#modal-id').modal();
                    },
                    clear:function(){
                        this.subject = {};
                    },
                    save:function () {
                        var reg = /^[\u4e00-\u9fa5]{2,5}$/
                        if(!this.subject.subType || !reg.test(this.subject.subType)){
                            alert("规则不匹配")
                            return false;
                        }
                        var param = {
                            subId:this.subject.subId,
                            subType:this.subject.subType,
                            subTime:this.subject.subTime,
                            remark:this.subject.remark
                        }
                        var that = this;
                        $.post(that.url+'/save',param,function (data) {
                            if(data){
                                alert("保存成功")
                                that.query();
                                that.clear();


                            }else{
                                alert("规则不匹配")

                            }
                        })

                    },
                    remove:function(id){
                        var that = this;
                        $('#type-delBox').dialogBox({
                            hasClose: true,
                            hasBtn: true,
                            width: 300,
                            height: 200,
                            confirmValue: '确认',
                            confirm: function(){
                                $.get(that.url+'/remove/'+id,function (data) {
                                    if(data!=null){
                                        that.query();


                                    }else{
                                        $('#type-delBox2').dialogBox({
                                            autoHide: true,
                                            time: 2000,
                                            width:300,
                                            height:60,
                                            content: '删除失败！'
                                        });
                                    }
                                })
                            },
                            cancelValue: '取消',
                            title: '提醒',
                            content: '你确定删除该科目信息吗！'
                        });
                       /* $.get(that.url+'/remove/'+id,function (data) {
                            if(data!=null){
                                alert("删除成功"+id)
                                that.query();
                                that.clear();

                            }else{
                                alert("删除失败"+id)

                            }
                        })*/
                    },
                    shot:function(){

                    }
                }
            });
            vue.query();
            $("#header").load("header.html");
            $("#left").load("left.html");

                })
    </script>
</head>
<body>
<div id="app" class="container-fluid bgcon">
    <div class="row" id="header">

    </div>
    <div class="row">
        <div class="col-md-2" id="left">

        </div>
        <div class="col-md-9"style="margin-left:100px;margin-top:10px">
            <div class="col-md-9">
                <div class="row tithead"><h3 class="glyphicon glyphicon-road"> 科目信息管理
                </h3>
                </div>
                <div class="row col-md-12" style="margin-bottom:20px">

                    <div class="col-md-3" >
                        <input v-model="subject.subType" class="form-control" placeholder="请输入科目类型名称">
                    </div>
                    <div class="col-md-3">
                        <input v-model="subject.subTime" class="form-control" placeholder="请输入科目时长">
                    </div>
                    <div class="col-md-2">
                        <input v-model="subject.remark" class="form-control" placeholder="备注信息">
                    </div>



                    <div class="col-md-2">
                        <button @click="clear" class="btn btn-default btn-block">取消</button>
                    </div>
                    <div class="col-md-2">
                        <button @click="save" class="btn btn-primary btn-block">保存</button>
                    </div>
                </div>

                <div class="row" style="margin-top: 15px">
                    <div class="col-md-12">
                        <div class="table-responsive">
                            <table class="table table-bordered table-striped table-hover text-center">
                                <thead>
                                <tr>
                                    <th class="text-center">序号</th>
                                    <th class="text-center">类型名称</th>
                                    <th class="text-center">科目时长</th>
                                    <th class="text-center">备注信息</th>
                                    <th class="text-center">编辑</th>
                                    <th class="text-center">删除</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr v-for="(s,index) in subjects">
                                    <td>{{index+1}}</td>
                                    <td>{{s.subType}}</td>
                                    <td>{{s.subTime}}</td>
                                    <td>{{s.remark}}</td>
                                    <td>
                                        <button @click="find(s)" class="btn btn-warning" href='#modal-id'>编辑</button>
                                    </td>
                                    <td>
                                        <button @click="remove(s.subId)" class="btn btn-danger">删除</button>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="row text-right remark"><h5>备注：科目信息分为科目一到科目四,科目一和四为10课时,科目二和三为30课时,为课程预约信息. </h5></div>
            </div>
        </div>
    </div>
</div>
<div id="type-delBox"></div>
<div id="type-delBox2"></div>
</body>
</html>